/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  NativeModules,
  Modal
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component {
  constructor(props){
    super(props);
    this.state={
      isVisible:true,
    }
  }
  closeModal(){
    this.setState({isVisible:!this.state.isVisible})
}
  render() {
    return (
      <View style={styles.container}>
        {
                    this.state.isVisible && Platform.OS == 'android'?
                <Modal
                    transparent={true}
                    visible={this.state.isVisible}
                    animationType={'fade'}
                    onRequestClose={() => this.closeModal()}>
                    <View style={styles.container} activeOpacity={1}>
                        <View style={{width:commonStyle.screenWidth-160,maxHeight:260,minHeight:100,backgroundColor:'#FFF'}}>
                            <View style={{alignItems:'center',justifyContent:'center'}}>
                                <Image style={{width:commonStyle.screenWidth-160,height:50}} source={require('./imgs/appUpdata.jpg')}/>
                                <Text style={{color:'#000',fontSize:18,position:'absolute',fontWeight:'bold'}}>发现新版本</Text>
                                <Text style={{position:'absolute',right:10,bottom:5,fontSize:12,backgroundColor:'#FFF',paddingLeft:5,paddingRight:5,borderRadius:10}}>V1.0.1</Text>
                            </View>
                           <View style={{marginTop:20,paddingLeft:15,paddingRight:15}}>
                               <Text>1 优化优化优化</Text>
                               <Text>1 优化优化优化</Text>
                               <Text>1 优化优化优化</Text>
                               <Text>1 优化优化优化</Text>
                               <Text>1 优化优化优化</Text>
                               <Text>1 优化优化优化</Text>
                           </View>
                           <View style={{marginTop:20,alignItems:'center',justifyContent:'center',paddingBottom:20}}>
                                <TouchableOpacity style={{width:commonStyle.screenWidth-220,height:36,alignItems:'center',justifyContent:'center',backgroundColor:'#c30b0bde',borderRadius:18}}
                                    onPress={()=>{
                                        NativeModules.DownloadApk.downloading("http://app.mzooe.com/app/app-release.apk","shishang.apk");
                                        this.setState({isVisible:!this.state.isVisible})
                                    }}
                                >
                                    <Text style={{color:'#FFF',fontSize:16}}>立即更新</Text>
                                </TouchableOpacity>
                           </View>
                        </View>
                    </View>
                </Modal>
                :null
                  }
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        alignItems:'center',justifyContent:'center'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
